//  this library.
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hktk_app/ienum/my/rank_type_enum.dart';
import 'package:hktk_app/ienum/practice/ct_enum.dart';
import 'package:hktk_app/ienum/question/first_type_enum.dart';
import 'package:hktk_app/model/subject/upload_collection_model.dart';
import 'package:hktk_app/pages/question/single_question_page.dart';
import 'package:hktk_app/util/my_util.dart';

import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/question/stem_rich_text_widget.dart';

/// 我的错题/收藏对应item显示
class ViewItemWidget extends StatelessWidget {
  /// 试题相关数据
  final UploadCollectionModel collModel;

  /// 类型，0是错题，1是收藏
  final RankTypeEnum type;

  const ViewItemWidget({
    super.key,
    required this.collModel,
    required this.type,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        _onTapFun(context);
      },
      child: Container(
        padding: EdgeInsets.all(30),
        decoration: BoxDecoration(
          border: Border(bottom: BorderSide(color: colorBlack5, width: 1)),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(child: _stemItem()),
            hiSpace(width: 20),
            _titleItemIcon(),
          ],
        ),
      ),
    );
  }

  /// 题干显示
  _stemItem() {
    return StemRichTextWidget(
      text: MyUtil.getQuesStemStr(
        type: FirstTypeEnum.getFirstTypeByCode(collModel.qt!),
        stem: collModel.st,
      ),
      textStyle: TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
    );
  }

  /// 标题右边显示
  _titleItemIcon() {
    return SvgPicture.asset(
      "images/my/wrong_question_icon.svg",
      width: 8,
      height: 16,
    );
  }

  /// 试题点击方法
  void _onTapFun(BuildContext context) {
    debugPrint("你点击了 ===> ${collModel.qid}");
    String pName = "我的收藏";
    CtEnum rType = CtEnum.rankCollect;
    if (type == RankTypeEnum.error) {
      rType = CtEnum.rankError;
      pName = "我的错题";
    }

    Navigator.pushNamed(context, "/single-question",arguments: {
      "collectId": collModel.cid ?? "",
      "paperName": collModel.cn ?? pName,
      "qId": collModel.qid!,
      "qType": FirstTypeEnum.getFirstTypeByCode(collModel.qt!),
      "rType": collModel.ct ?? rType,
    });
  }
}
